<?php
/**
 * Created by PhpStorm.
 * User: 戎大富
 * Date: 2020/10/13
 * Time: 9:11
 */
namespace app\api\controller;
use think\Db;
class Yue extends Base {
    private $user_id; // 用户ID
    private $page; // 页码
    private $create_time;

    /**
     * 异地登录验证
     * @return string
     */
    public function __construct()
    {
        $this->language = input('language') ? input('language') : 0;
        $this->user_id = input('user_id');
        $this->page = input('page') ? input('page') : 1;
        $this->create_time = date('Y-m-d H:i:s');
        $time = input('time');
        $value = input('value');
        $reqKey = input('reqKey');
        $auth = $this->checkAll($this->user_id, $time, $value, $reqKey);
        if($auth == 112){
            echo json_encode(['status'=>301, 'msg'=>$this->msg_language->otherLogin[$this->language]]);
            exit;
        }elseif($auth == 2111){
            echo json_encode(['status' => 303, 'msg' => $this->msg_language->frost[$this->language]]);
            exit;
        }
    }
    //首页
    public function index(){
        $time = input('param.time');
        $cycle = input('param.cycle');
        $budget = input('param.budget');
        $order = '';
        if($time==1){
            $order .='yue_time desc,';
        }elseif ($time==2){
            $order .='yue_time asc,';
        }else{
            $order .='yue_time desc,';
        }
        if($cycle==1){
            $order .='yue_day_num desc,';
        }elseif ($cycle==2){
            $order .='yue_day_num asc,';
        }
        if($budget==1){
            $order .='yue_price desc,';
        }elseif ($budget==2){
            $order .='yue_price asc,';
        }
        $order = trim($order,',');
        $res = Db::table('up_yue')->order($order)
            ->field('yue_id,yue_title,yue_price,yue_day_num,yue_time')
            ->where('yue_stat', 1)
            ->page($this->page,15)
            ->select();
        return json(['status' => 200, 'msg' => $res]);
    }
    //详情
    public function yueDetail(){
        $yue_id = input('param.yue_id');
        $where['a.yue_id'] = $yue_id;
        $res = Db::table('up_yue')->alias('a')
            ->join('up_u_user uuu','uuu.user_id = a.yue_user_id','left')
            ->field('a.yue_id,uuu.user_username,uuu.user_image,a.yue_explain,
                    a.yue_title,a.yue_price,a.yue_day_num,a.yue_time,a.yue_user_id')
            ->find();
        return json(['status' => 200, 'msg' => $res]);
    }
    //我要应征
    public function enlist(){
        $yue_id = input('param.yue_id');
        $data['yju_user_id'] = $this->user_id;
        $data['yju_yue_id'] = $yue_id;
        $data['yju_time'] = date('Y-m-d H:i:s');
        $res = Db::table('up_yue_join_user')->insertGetId($data);
        if($res){
            return json(['status' => 200, 'msg' => "成功"]);
        }else{
            return json(['status' => 100, 'msg' => "失败"]);
        }
    }
    //举报类型
    public function reportType(){
        $res = Db::table('up_yue_report_type')->select();
        return json(['status' => 200, 'msg' => $res]);
    }

    //举报
    public function report(){
        $yue_id = input('param.yue_id');
        $yue_report_type_id = input('param.yue_report_type_id');
        $data['yue_id'] = $yue_id;
        $data['report_user_id'] = $this->user_id;
        $data['yue_report_type_id'] = $yue_report_type_id;
        $data['report_time'] = date('Y-m-d H:i:s');
        $res = Db::table('up_yue_report')->insertGetId($data);
        if($res){
            return json(['status' => 200, 'msg' => "成功"]);
        }else{
            return json(['status' => 100, 'msg' => "失败"]);
        }
    }

}